package gudao.red.protobuf;

import com.google.common.io.Files;
import gudao.red.protobuf.PersonFactory;

import java.io.File;
import java.net.Socket;

public class Client {
      
    public static void main(String[] args) throws Exception {  
//        Socket socket = new Socket("127.0.0.1",3030);
          
        PersonFactory.Person.Builder person = PersonFactory.Person.newBuilder();
          
        PersonFactory.Addr.Builder addr = PersonFactory.Addr.newBuilder();
        addr.setContry("china").setCity("shenzhen");  
          
        person.setId(1).setAge(12).setName("ccf");  
        person.setAddr(addr);  
          
        byte[] messageBody = person.build().toByteArray();  
      
        int headerLen = 1;  
        byte[] message = new byte[headerLen+messageBody.length];  
        message[0] = (byte)messageBody.length;  
        System.arraycopy(messageBody, 0,  message, 1, messageBody.length);  
        System.out.println("msg len:"+message.length);  
//        socket.getOutputStream().write(message);


        Files.write(message,new File("C:\\Users\\Administrator\\Desktop\\pb.byte"));
    }  
  
}  